import Vue from "vue";
import Vuex from "vuex";
Vue.use(Vuex);
const store = new Vuex.Store({
  // Vue.set(state,"age",15)
  // Vue.delete(state,'age')
  state: {
    left_nav_flag: false, //左侧导航padding
    classify_options: [], //行业分类
    search_result_options: null,
    province_city: [], //省份城市
    is_vip: 0, //省份城市
    goodsKindArrNew: [],  //新商品分类
    goodsKindArrList: [], //旧商品分类
    goodsSerchOptions: null, //商品搜索条件
    liveSearchOptions: null, //直播搜索条件
    //存放的键值对就是所要管理的状态
    name: "大王莉",
    age: 18,
    //行业
    industry: [],
    startDate: "",
    endDate: "",
    //小店来源
    source: "",
    //品类
    goodKind: "",
    //价格区间
    price: "",
    goodsWords: "",
    //商品单价
    pricenum: "",
    //佣金率
    brokerage: "",
    // 达人id
    AuthorId: "", // 账号诊断搜索结果数据
    accountDiagnosisList: "", // 诊断记录id
    diagId: null, // 用户id
    authorId: null,
    userInfo: null, //用户信息
    userRoot: null, //用户权限
    userRootData: null, //用户权限(给续费页面用，不用再次请求接口)
    talentCompare: [], //达人对比
    liveCompare: [], //直播间对比
    search_wen: [], //主页搜索记录
    // history:false, // 头部控制搜索记录显示隐藏
    isHuoDongPopup: false, //活动弹窗
    isVipPopup: false, //会员弹窗
    register: false,
    dialog01:false,  // 对公转账
    speedShow:window.localStorage.getItem("speedShow"),
    isPopLoginBox:false,  //是否弹出登录框
    loginedUrl:'',  //登录成功之后的跳转地址
  },
  mutations: {
     // 一件提速
     loginedUrl(state, payload) {
      state.loginedUrl = payload;
    },
     // 是否弹出登录框
     isPopLoginBox(state, payload) {
      state.isPopLoginBox = payload;
    },
     // 一件提速
     speedShow_change(state,payload){
      state.speedShow=payload;
      window.localStorage.setItem("speedShow",payload)
    },
    // 对公转账
    dialog01(state,payload){
      state.dialog01=payload;
    },
    // 
    registerChange(state, payload) {
      state.register = payload;
    },
    userInfo(state, payload) {
      state.userInfo = payload;
    },
    huoDongPopup(state, payload) {
      state.isHuoDongPopup = payload;
    },
    getSvipPopup(state, payload) {
      state.isVipPopup = payload;
    },
    reachHistory(state, payload) {
      state.history = payload;
    },
    talentCompare(state, payload) {
      state.talentCompare = payload;
    },
    liveCompare(state, payload) {
      state.liveCompare = payload;
    },
    userRoot(state, payload) {
      state.userRoot = payload;
    },
    userRootData(state, payload) {
      state.userRootData = payload;
    },
    diagId(state, payload) {
      state.diagId = payload;
    },
    authorId(state, payload) {
      state.authorId = payload;
    },
    accountDiagnosisList(state, payload) {
      state.accountDiagnosisList = payload;
    },
    change_AuthorId(state, payload) {
      state.AuthorId = payload;
    },
    change_pricenum(state, payload) {
      state.pricenum = payload;
    },
    change_brokerage(state, payload) {
      state.brokerage = payload;
    },
    change_goodsWord(state, payload) {
      state.goodsWords = payload;
    },
    change_source(state, payload) {
      state.source = payload;
    },
    change_goodKind(state, payload) {
      state.goodKind = payload;
    },
    change_price(state, payload) {
      state.price = payload;
    },
    change_is_vip(state, payload) {
      state.is_vip = payload;
    },
    change_province_city(state, payload) {
      state.province_city = payload;
    },
    change_search_result_options(state, payload) {
      state.search_result_options = payload;
    },
    change_search_result_options_sort(state, payload) {
      state.search_result_options.sort = payload;
    },
    change_search_result_options_page(state, payload) {
      state.search_result_options.page = payload;
    },
    change_left_nav_flag(state, payload) {
      state.left_nav_flag = payload.flag;
    },
    change_classify_options(state, payload) {
      state.classify_options = payload.arr;
    },
    changeGoodsKindArrNew(state, payload) { //新商品分类
      state.goodsKindArrNew = payload.arr;
    },
    changegoodsKindArrList(state, payload) {  //新商品分类 - 处理过的 [[分类名称],[分类id]]
      state.goodsKindArrList = payload.arr;
    },
    //行业
    changeindustryArr(state, payload) {
      state.industry = payload;
    },
    // this.$store.commit('edit')
    // this.$store.commit('edit',{age:15,sex:'男'})
    edit(state) {
      state.name = "jack";
    },
    edit_01(state, payload) {
      setTimeout(() => {
        state.name = payload.name;
      }, 2000);
    },
    // 商品搜索
    changeGoodsSearch(state, payload) {
      state.goodsSerchOptions = payload;
    },
    changeGoodsSearch_page(state, payload) {
      state.goodsSerchOptions.pageIndex = payload;
    },
    changeGoodsSearch_sort(state, payload) {
      state.goodsSerchOptions.sort = payload;
    },
    // 直播搜索
    changeLiveSearch(state, payload) {
      state.liveSearchOptions = payload;
    },
    changeLiveSearch_page(state, payload) {
      state.liveSearchOptions.page = payload;
    },
    changeLiveSearch_sort(state, payload) {
      state.liveSearchOptions.sort = payload;
    },
    changestartDate(state, payload) {
      state.startDate = payload;
    },
    changeendDate(state, payload) {
      state.endDate = payload;
    }
  },
  getters: {
    // this.$store.getters.fullInfo
    nameInfo(state) {
      return "姓名:" + state.name;
    },
    fullInfo(state, getters) {
      return getters.nameInfo + "年龄:" + state.age;
    }
  },
  actions: {
    // this.$store.dispatch('aEdit',{age:15})
    aEdit(context, payload) {
      setTimeout(() => {
        context.commit("edit", payload);
      }, 2000);
    }

    // 优化
    // aEdit(context,payload){
    //     return new Promise((resolve,reject)=>{
    //         setTimeout(()=>{
    //             context.commit('edit',payload)
    //             resolve()
    //         },2000)
    //     })
    // }
  }
});

export default store;
